package services;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import repository.GenericConector;
import model.Reservas;

public class ReservasServices {
	
	private List<Reservas> lista;
	private GenericConector gc;
	private ResultSet rs;
	
	public List<Reservas> GetReservas() throws SQLException{
		gc = new GenericConector();
		rs = gc.getResultSet("SELECT ifnull(max(idreservas),0) as max FROM reservas");
		lista = new ArrayList<Reservas>();
		
		while(rs.next()){
			lista.add(new Reservas(rs.getInt("idreservas"), rs.getInt("idppaquete"), rs.getInt("idvuelo")));
		}
		
		return lista;
	}
	
	public void UpdateReserva (Reservas reserva) throws SQLException{
		gc = new GenericConector();
		gc.ejecutar("UPDATE Reservas"
				+ "SET idppaquete = " + reserva.getIdpaquete()
				+ ", idvuelo = " + reserva.getIdvuelo()
				+ "WHERE idreservas = " + reserva.getIdreservas());
	}
	
	public void SaveReserva(List<Reservas> listaSave) throws SQLException{
		gc = new GenericConector();
		for(Reservas reserva : listaSave){
			gc.ejecutar("insert into reservas (idreservas,idpaquete,idvuelo) values(" + reserva.getIdreservas() + "," + reserva.getIdpaquete() + "," + reserva.getIdvuelo() + ")");
		}
	}

}
